package com.itheima.test;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ButtonClick {
    public static void main(String[] args) {

        JFrame jFrame = new JFrame();
        jFrame.setTitle("测试点击按钮");
        jFrame.setSize(400,400);
        jFrame.setLocationRelativeTo(null);
        jFrame.setLayout(null);
        jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        //创建按钮
        JButton jButton = new JButton("点击我");
        jButton.setBounds(0,0,100,50);

        //创建监听事件 使用匿名内部类
        jButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
               System.out.println("我被点击了");
            }
        });

        //添加按钮
        jFrame.getContentPane().add(jButton);

        jFrame.setVisible(true);

    }
}
